const app = getApp();
Component({
  properties: {
    navbarData: {
      observer: function (newVal, oldVal) {
        if (newVal) {
          this.setData({
            navbarData: newVal
          });
        }
      }
    },
    prevent: Boolean,
    noShowBackImg: Boolean
  },
  data: {},
  attached: async function () {
    // 定义导航栏的高度   方便对齐
    var navPosition = wx.getMenuButtonBoundingClientRect();
    this.setData({
      navPosition,
      menuButtonBounding: app.globalData.menuButtonBounding
    });
    for (let i = 0; i < 5; i++) {
      this.setData({ navPosition: wx.getMenuButtonBoundingClientRect() })
      await new Promise(resolve => setTimeout(resolve, 200))
    }
  },
  pageLifetimes: {},
  methods: {
    // 返回上一页面
    _navback() {
      if (!this.data.prevent) {
        let pageNum = getCurrentPages().length;
        if (pageNum == 1) {
          wx.redirectTo({
            url: '/pages/init/index'
          });
        } else wx.navigateBack();
      } else {
        this.triggerEvent('onBack');
      }
    },
  }
});